﻿/*
Digraph (library for building, traversal, comparison and saving of directed
graph).

Copyright (C) 2014 Dmitry Merzagitovich Arslanov

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/

// How to compare two digraphs.
namespace Sample5
{
    using System;

    // Define digraph types.
    using Vertex = Digraph.Vertex<string, string>;
    using Arc = Digraph.Arc<string, string>;
    using Graph = Digraph.Set<string, string>;
    using Builder = Digraph.Builder<string, string>;
    using Diff = Digraph.Difference<string, string>;

    public static class App
    {
        public static void Main()
        {
            // Create first digraph.
            Builder b1 = new Builder();
            Vertex g1v1 = b1.NewVertex("v1");
            Vertex g1v2 = b1.NewVertex("v2");
            Vertex g1v3 = b1.NewVertex("v3");
            b1.NewArc(g1v1, g1v2, "a1");
            b1.NewArc(g1v1, g1v3, "a2");
            Graph g1 = b1.Digraph;
            // Create second digraph.
            Builder b2 = new Builder();
            Vertex g2v1 = b2.NewVertex("v1");
            Vertex g2v2 = b2.NewVertex("v2");
            Vertex g2v4 = b2.NewVertex("v4");
            b2.NewArc(g2v1, g2v2, "a1");
            b2.NewArc(g2v1, g2v4, "a3");
            Graph g2 = b2.Digraph;
            // Second digraph is first digraph after followed changes:
            // v4 is added in digraph.
            // a3 is added in digraph.
            // v3 is removed from digraph.
            // a2 is removed from digraph.
            // Compare two digraphs and get its difference containing the
            // changes.
            Diff d = Graph.Compare(g1, g2);
            // Print changes.
            Console.WriteLine("Added vertices:");
            foreach (Vertex v in d.AddedVertices)
            {
                Console.WriteLine(v.Content);
            }
            Console.WriteLine("Added arcs:");
            foreach (Arc a in d.AddedArcs)
            {
                Console.WriteLine(a.Content);
            }
            Console.WriteLine("Removed vertices:");
            foreach (Vertex v in d.RemovedVertices)
            {
                Console.WriteLine(v.Content);
            }
            Console.WriteLine("Removed arcs:");
            foreach (Arc a in d.RemovedArcs)
            {
                Console.WriteLine(a.Content);
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }
}

#region Program output is shown below in comments
/*
Added vertices:
v4
Added arcs:
a3
Removed vertices:
v3
Removed arcs:
a2
Press any key to exit...
*/
#endregion
